using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Database
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class DbKey : IComparable 
    {
        private DataProviderType _DbProviderType;
        private string _ConnStr;
        private string _Key;

        /// <summary>
        /// 
        /// </summary>
        public DbKey()
        {
            this.DbProviderType = DataProviderType.MSSQL;
            this.ConnStr = "Server=(local);Database=Master;Integrated Security=true;";
            this.Key = "{"+((int) this.DbProviderType).ToString() + "}{" + this.ConnStr + "}";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dbproviderType"></param>
        /// <param name="connStr"></param>
        public DbKey(DataProviderType dbproviderType, string connStr)
        {
            this.DbProviderType = dbproviderType;
            this.ConnStr = connStr;
            this.Key = "{" + ((int)this.DbProviderType).ToString() + "}{" + this.ConnStr + "}";
        }

        /// <summary>
        /// 
        /// </summary>
        public DataProviderType DbProviderType
        {
            get { return _DbProviderType; }
            set { _DbProviderType = value; }
        }
        /// <summary></summary>
        public string ConnStr
        {
            get { return _ConnStr; }
            set { _ConnStr = value; }
        }
        /// <summary></summary>
        public string Key
        {
            get { return _Key; }
            set { _Key = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            if (obj.GetType() == typeof(DbKey))
            {
                DbKey otherKey = (DbKey)obj;
                return this.Key.ToLower().CompareTo(otherKey.Key.ToLower());
            }
            else
            {
                throw new Exception("Comparable object must be of type DbKey");
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.Key.ToLower().GetHashCode();
        }
    }
}
